package com.aim.analysis.questionnaire;

import com.aim.azure.AzureDemographicEntity;
import com.aim.azure.AzureGameQuestionnaireEntity;

/**
 * User: Avraham Shvartzon
 * Date: 6/17/14
 */
public class QuestionnaireRecord {

    public String partitionKey;
    public String workerId;


    public String gender;
    public int age;

    public int enjoyGame;
    public int performanceSelfAssessment;
    public String alertFrequency;
    public String setFrequency;
    public int secondsInAdvanceForAlert;
    public int maintenanceAlertsHelpful;
    public String gameStrategyDesc;
    public int takeRisks;
    public String bugsOccured;
    public String bugDescriptionIfExist;
    public String freeText;

    public QuestionnaireRecord(String workerId, String partitionKey, String gender, int age, int enjoyGame, int performanceSelfAssessment, String alertFrequency, String setFrequency, int secondsInAdvanceForAlert, int maintenanceAlertsHelpful, String gameStrategyDesc, int takeRisks, String bugsOccured, String bugDescriptionIfExist, String freeText) {
        this.workerId = workerId;
        this.gender = gender;
        this.age = age;
        this.partitionKey = partitionKey;
        this.enjoyGame = enjoyGame;
        this.performanceSelfAssessment = performanceSelfAssessment;
        this.alertFrequency = alertFrequency;
        this.setFrequency = setFrequency;
        this.secondsInAdvanceForAlert = secondsInAdvanceForAlert;
        this.maintenanceAlertsHelpful = maintenanceAlertsHelpful;
        this.gameStrategyDesc = gameStrategyDesc;
        this.takeRisks = takeRisks;
        this.bugsOccured = bugsOccured;
        this.bugDescriptionIfExist = bugDescriptionIfExist;
        this.freeText = freeText;
    }

    public static QuestionnaireRecord create(AzureGameQuestionnaireEntity e, AzureDemographicEntity d){
        int age = 0;
        String gender = "";
        String workerId = "N/A";
        if (d != null) {
            age = (int) Double.parseDouble(d.Age);
            gender = d.Gender;
            workerId = d.WorkerId;
        }

        int enjoyGame = parseInt(e.EnjoyGame,-1);
        int performanceSelfAssessment = parseInt(e.PerformanceSelfAssessment,-1);
        int secondsInAdvanceForAlert = parseInt(e.SecondsInAdvanceForAlert,-1);
        int maintenanceAlertsHelpful = parseInt(e.MaintenanceAlertsHelpful,-1);
        int takeRisks = parseInt(e.TakeRisks, -1);


        QuestionnaireRecord record = new QuestionnaireRecord(
                workerId, e.PartitionKey, gender,
                age,
                enjoyGame,
                performanceSelfAssessment,
                e.AlertFrequency,
                e.SetFrequency,
                secondsInAdvanceForAlert,
                maintenanceAlertsHelpful,
                e.GameStrategyDesc,
                takeRisks,
                e.BugsOccured,
                e.BugDescriptionIfExist,
                e.FreeText
        );
        return record;
    }

    private static int parseInt(String valueStr, int defaultValue){
        int value;
        try{
        value = Integer.parseInt(valueStr);
        } catch (Exception e){
            return defaultValue;
        }
        return value;
    }


}
